function [ FList ] = CalculateFundamentalMatrixOutOf7( x,X)
[T1 x]=normalize(x);
[T2 X]=normalize(X);
n = size(x,2);
A = zeros(n,9);
for i=1:n
    x1 = x(1,i);
    y1 = x(2,i);
    x2 = X(1,i);
    y2 = X(2,i);
    
    A(i,1) = x2*x1;
    A(i,2) = x2*y1;
    A(i,3) = x2;
    A(i,4) = y2*x1;
    A(i,5) = y2*y1;
    A(i,6) = y2;
    A(i,7) = x1;
    A(i,8) = y1;
    A(i,9) = 1;
end

ns = null(A);
f1 = ns(:,1);
f2 = ns(:,2);

F1 = reshape(f1,3,3);
F2 = reshape(f2,3,3);

F = cell(2);
F{1} = F1;
F{2} = F2;

%solve the eq  det( a*F{1} + (1-a)*F{2} ) == 0. 
a = vgg_singF_from_FF(F);

FList = cell(size(a,1));

%construct F for any result a
for i=1:length(FList)
    FList{i} = a(i)*F1 + (1-a(i))*F2;
    FList{i}=T2'*FList{i}*T1;
end

end



%VGG_SINGF_FROM_FF  Linearly combines two 3x3 matrices to a singular one. 
% 
%   a = vgg_singF_from_FF(F)  computes scalar(s) a such that given two 3x3 matrices F{1} and F{2}, 
%   it is det( a*F{1} + (1-a)*F{2} ) == 0. 
 
function a = vgg_singF_from_FF(F) 
 
% precompute determinants made from columns of F{1}, F{2} 
for i1 = 1:2 
  for i2 = 1:2 
    for i3 = 1:2 
      D(i1,i2,i3) = det([F{i1}(:,1) F{i2}(:,2) F{i3}(:,3)]); 
    end 
  end 
end 
 
% Solve The cubic equation for a 
a = roots([-D(2,1,1)+D(1,2,2)+D(1,1,1)+D(2,2,1)+D(2,1,2)-D(1,2,1)-D(1,1,2)-D(2,2,2) 
            D(1,1,2)-2*D(1,2,2)-2*D(2,1,2)+D(2,1,1)-2*D(2,2,1)+D(1,2,1)+3*D(2,2,2) 
            D(2,2,1)+D(1,2,2)+D(2,1,2)-3*D(2,2,2) 
            D(2,2,2)]); 
a = a(abs(imag(a))<10*eps); 
 
end

